#include "comm/znx_crc.h"

int main() {
    DD("crc16: %d", znx_crc16((const u_char *)"abcdef", strlen("abcdef")));
    DD("crc32 short: %d", znx_crc32_short((const u_char *)"abcdef", strlen("abcdef")));
    DD("crc32 long: %d", znx_crc32_long((const u_char *)"abcdef", strlen("abcdef")));


    const char *str = "aaaaabbbbbbbbccccccddddeeeeeffffffgggggghhhhhhhhhhiiiiiiiiiiijjjjjjjjjj"
                      "kkkkkkllllllmmmmmmmnnnnnnnnnooooooopppppqqqqqqqqrrrrrrrrsssssssttttttt"
                      "1111111122222222222233333333333344444444444455555555555555566666666666"
                      "7777777888888888899999999999999000000000000000000000000000000000000000";
    DD("crc32 short: %u", znx_crc32_short((const u_char *)str, strlen(str)));
    DD("crc32 long: %u", znx_crc32_long((const u_char *)str, strlen(str)));

    uint32_t crc_sum = 0;
    znx_crc32_init(crc_sum);
    const char *str1 = "aaaaabbbbbbbbccccccddddeeeeeffffffgggggghhhhhhhhhhiiiiiiiiiiijjjjjjjjjj";
    znx_crc32_update(&crc_sum, (const u_char *)str1, strlen(str1));
    const char *str2 = "kkkkkkllllllmmmmmmmnnnnnnnnnooooooopppppqqqqqqqqrrrrrrrrsssssssttttttt";
    znx_crc32_update(&crc_sum, (const u_char *)str2, strlen(str2));
    const char *str3 = "1111111122222222222233333333333344444444444455555555555555566666666666";
    znx_crc32_update(&crc_sum, (const u_char *)str3, strlen(str3));
    const char *str4 = "7777777888888888899999999999999000000000000000000000000000000000000000";
    znx_crc32_update(&crc_sum, (const u_char *)str4, strlen(str4));
    znx_crc32_final(crc_sum);

    if (crc_sum != znx_crc32_short((const u_char *)str, strlen(str))) {
        DD_FATAL("except %u, but got %u", znx_crc32_short((const u_char *)str, strlen(str)), crc_sum);
    }

    size_t len = strlen("www.abc.com");
    u_char *raw = (u_char *)"WWW.abc.CoM";
    u_char *lower = (u_char *)"www.abc.com";

    if (znx_crc32_short_lower(raw, len) != znx_crc32_short(lower, len)) {
        DD_FATAL("expect true, but got false");
    }

    if (znx_crc32_short_lower(raw, len) == znx_crc32_short(raw, len)) {
        DD_FATAL("expect false, but got true");
    }

    if (znx_crc32_long_lower(raw, len) != znx_crc32_long(lower, len)) {
        DD_FATAL("expect true, but got false");
    }

    if (znx_crc32_long_lower(raw, len) == znx_crc32_long(raw, len)) {
        DD_FATAL("expect false, but got true");
    }


    DD("test pass");
    return 0;
}